<?php

    class LeerlingRepository implements IRepository 
    {
        private $client;

        public function __construct($client)
        {
            $this->client = $client;
        }
        
        public function Create()
        {
        }
        
        public function Read()
        {
        }
        
        public function Update($id)
        {
        }
        
        public function Delete($id)
        {
        }
        
        public function Leerling($id)
        {
            $link = $this->client->connect();
            $query = "SELECT * FROM `leerling`
                    JOIN `pakket` ON `leerling`.pakket_id = `pakket`.id
                    WHERE `leerling`.id = " . $id . ";";
            $result = mysql_query($query);
            $leerlingen = array();
            if($result !== false)
            {
                while($row = mysql_fetch_assoc($result))
                {
                    if(isset($row['id']))
                    {
                        $leerlingen[] = $row;
                    }
                }
            }
            else
            {
                echo mysql_error();
            }
            $this->client->close();
            return $leerlingen;
        }
        
        public function AlleLeerlingenVan($gebruikersId)
        {
            $link = $this->client->connect();
            $query = "SELECT * FROM leerling WHERE instructeur_id = '" . $gebruikersId . "';";
            $result = mysql_query($query);
            $leerlingen = array();
            if($result !== false)
            {
                while($row = mysql_fetch_assoc($result))
                {
                    if(isset($row['id']))
                    {
                        $leerling = array
                        (
                            "id" => $row["id"],
                            "naam" => $row["naam"],
                        );
                       array_push($leerlingen,  $leerling);
                    }
                }
            }
            else
            {
                echo mysql_error();
            }
            $this->client->close();
            return $leerlingen;
        }
        
        public function AlleLeerlingen()
        {
            
        }
    }
?>